package com.hksj.base.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hksj.base.query.AlarmNumOverviewQuery;
import com.hksj.base.query.AlarmQuery;
import com.hksj.base.query.AlarmRankQuery;
import com.hksj.base.service.DefaultAlarmService;
import com.hksj.base.vo.AlarmNumOverviewVO;
import com.hksj.base.vo.AlarmRankVO;
import com.hksj.base.vo.AlarmRecordVO;
import com.hksj.common.core.model.Rest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "通用-报警记录")
@RestController
@RequestMapping("/api/comm/alarm")
public class DefaultAlarmController {
    @Autowired
    private DefaultAlarmService defaultAlarmService;

    @ApiOperation(value = "分页查询设备历史报警记录",response = AlarmRecordVO.class)
    @PostMapping("/pageAlarmHistory")
    public Rest<Page<AlarmRecordVO>> pageAlarmHistory(@RequestBody @Validated AlarmQuery query){
        Page<AlarmRecordVO> page = defaultAlarmService.pageAlarmHistory(query);
        return Rest.ok(page);
    }

    @ApiOperation("设备报警次数排名")
    @PostMapping("/listDeviceAlarmRank")
    public Rest<List<AlarmRankVO>> listDeviceAlarmRank(@RequestBody @Validated AlarmRankQuery query){
        List<AlarmRankVO> list = defaultAlarmService.listDeviceAlarmRank(query);
        return Rest.ok(list);
    }

    @ApiOperation("本日/本周/本月报警数")
    @PostMapping("/getAlarmNumOverview")
    public Rest<AlarmNumOverviewVO> getAlarmNumOverview(@RequestBody AlarmNumOverviewQuery query){
        return Rest.ok(defaultAlarmService.getAlarmNumOverview(query));
    }
}
